package com.example.wordbook;

import android.content.Context;
import android.os.Bundle;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.NavigationUI;

import pl.com.salsoft.sqlitestudioremote.SQLiteStudioService;

public class MainActivity extends AppCompatActivity {
    private NavController navController;
    //导航控制器，它负责操作Navigation框架下的Fragment的跳转与退出、动画、监听当前Fragment信息
    Button button;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //设置了视图导航，再activity里获取实例
        navController = Navigation.findNavController((findViewById(R.id.fragment)));
        SQLiteStudioService.instance().start(this); //启动SQLite服务

        NavigationUI.setupActionBarWithNavController(this, navController);//返回图标，但不生效
    }


    @Override
    public void onBackPressed() {
        super.onBackPressed();
        navController.navigateUp();
        //执行返回上一级Fragment的功能
    }


    //处理因点击返回自设按键键盘不收回的设置
    @Override
    public boolean onSupportNavigateUp() {
        //返回界面时隐藏键盘的操作
        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(findViewById(R.id.fragment).getWindowToken(), 0);//两个参数
        navController.navigateUp();
        return super.onSupportNavigateUp();//使返回按钮生效，不然没有反应，返回上一级fragment
    }


}
